home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / GenerateCertificateDlg.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  3KB  |  116 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20. #include "filezilla server.h"
  21. #include "GenerateCertificateDlg.h"
  22. #include "../AsyncSslSocketLayer.h"
  23. #include ".\generatecertificatedlg.h"
  24.  
  25. IMPLEMENT_DYNAMIC(CGenerateCertificateDlg, CDialog)
  26. CGenerateCertificateDlg::CGenerateCertificateDlg(CWnd* pParent /*=NULL*/)
  27.     : CDialog(CGenerateCertificateDlg::IDD, pParent)
  28.     , m_city(_T(""))
  29.     , m_cname(_T(""))
  30.     , m_country(_T(""))
  31.     , m_email(_T(""))
  32.     , m_file(_T(""))
  33.     , m_organization(_T(""))
  34.     , m_state(_T(""))
  35.     , m_unit(_T(""))
  36.     , m_keysize(0)
  37. {
  38. }
  39.  
  40. CGenerateCertificateDlg::~CGenerateCertificateDlg()
  41. {
  42. }
  43.  
  44. void CGenerateCertificateDlg::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CDialog::DoDataExchange(pDX);
  47.     DDX_Text(pDX, IDC_CITY, m_city);
  48.     DDX_Text(pDX, IDC_CNAME, m_cname);
  49.     DDX_Text(pDX, IDC_COUNTRY, m_country);
  50.     DDV_MaxChars(pDX, m_country, 2);
  51.     DDX_Text(pDX, IDC_EMAIL, m_email);
  52.     DDX_Text(pDX, IDC_FILE, m_file);
  53.     DDX_Text(pDX, IDC_ORGANIZATION, m_organization);
  54.     DDX_Text(pDX, IDC_STATE, m_state);
  55.     DDX_Text(pDX, IDC_UNIT, m_unit);
  56.     DDX_Radio(pDX, IDC_KEYSIZE1, m_keysize);
  57. }
  58.  
  59.  
  60. BEGIN_MESSAGE_MAP(CGenerateCertificateDlg, CDialog)
  61.     ON_BN_CLICKED(IDOK, OnOK)
  62.     ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  63. END_MESSAGE_MAP()
  64.  
  65. void CGenerateCertificateDlg::OnOK()
  66. {
  67.     UpdateData(TRUE);
  68.     if (m_country.GetLength() != 2)
  69.     {
  70.         AfxMessageBox(_T("Please enter the 2 digit country code"));
  71.         return;
  72.     }
  73.  
  74.     if (m_file == _T(""))
  75.     {
  76.         AfxMessageBox(_T("Please enter a filename"));
  77.         return;
  78.     }
  79.  
  80.     m_country.MakeUpper();
  81.  
  82.     int bits = 1024;
  83.     if (m_keysize == 1)
  84.         bits = 2048;
  85.     else if (m_keysize == 2)
  86.         bits = 4096;
  87.  
  88.     CString error;
  89.     USES_CONVERSION;
  90.     if (CAsyncSslSocketLayer::CreateSslCertificate(LPCTSTR(m_file), bits, (unsigned char*)T2CA(m_country),
  91.         (unsigned char*)T2CA(m_state), (unsigned char*)T2CA(m_city), (unsigned char*)T2CA(m_organization), (unsigned char*)T2CA(m_unit),
  92.         (unsigned char*)T2CA(m_cname), (unsigned char*)T2CA(m_email), error))
  93.     {
  94.         AfxMessageBox(_T("Certificate generated successfully."));
  95.         EndDialog(IDOK);
  96.     }
  97.     else
  98.     {
  99.         if (error != _T(""))
  100.             AfxMessageBox(_T("Certificate could not be generated.\nReason: ") + error);
  101.         else
  102.             AfxMessageBox(_T("Certificate could not be generated."));
  103.     }
  104. }
  105.  
  106. void CGenerateCertificateDlg::OnBrowse()
  107. {
  108.     UpdateData();
  109.     CFileDialog dlg(FALSE, 0, _T("certificate.crt"));
  110.     if (dlg.DoModal() == IDOK)
  111.     {
  112.         m_file = dlg.GetPathName();
  113.         UpdateData(FALSE);
  114.     }
  115. }
  116.